package org.example.websocket;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

/**
 * @author wxm
 * @date 2025/3/4 18:03
 */
@Controller
public class WebSocketController {
    @MessageMapping("/test")
    @SendTo("/topic/test")
    public WebSocketMessage handleTestMessage(WebSocketMessage message) {
        if ("test".equals(message.getAction())) {
            System.out.println("Received test action message: " + message.getContent());
            // 构造响应消息
            return new WebSocketMessage("test", "Server received your test message: " + message.getContent());
        }
        return null;
    }
}
